﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace RAMED
{
    public partial class CarteForm : Form
    {
        public Bordereau_Form bordereauform = new Bordereau_Form();

        public object carte { get; set; }

        
       
        public CarteForm()
        {
            InitializeComponent();
            RAMEDEntities1 Context = SingletonContext.GetContext();
            comboBoxcentresante.DataSource = Context.Centre_sante;
            comboBoxcentresante.DisplayMember = "nom_centre_sante";
            comboBoxcentresante.ValueMember = "id_centre_sante";
        }

        private void CarteForm_Load(object sender, EventArgs e)
        {

        }

        private void btnajouter_Click(object sender, EventArgs e)
        {
            if(ValidateChildren(ValidationConstraints.Enabled))
            {

             RAMEDEntities1 Context = SingletonContext.GetContext();
             Carte carteajouter = new Carte();
            carteajouter.Nom_benefi = txtnom.Text;
            carteajouter.Prenom_benefi = txtprenom.Text;
            carteajouter.CIN_benefi = txtcin.Text;
            carteajouter.IPCM = txtipcm.Text;
            carteajouter.Centre_sante = ((Centre_sante)comboBoxcentresante.SelectedItem);      
            bordereauform.Cartebordereau.Add(carteajouter);
            Context.SaveChanges();
            bordereauform.mettreAjourFormGridView();
            
            
            this.Dispose();
  
            }
        }
           

        private void button2_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void Button21_Click(object sender, EventArgs e)
        {
            this.WindowState =  FormWindowState.Minimized;
        }

        private void txtnom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs Nom est obligatoire", txtnom, e, errorProvider1);
        }

        private void txtprenom_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs prénom est obligatoire", txtprenom, e, errorProvider1);
        }

        private void txtcin_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("le champs cin est obligatoire", txtcin, e, errorProvider1);
        }

        private void txtipcm_Validating(object sender, CancelEventArgs e)
        {
            utitlitaire.ValiderChampsRecquit("saisez un nombre valide", txtipcm, e, errorProvider1);
        }

        private void txtnom_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtprenom_TextChanged(object sender, EventArgs e)
        {

        }

        private void txtcin_TextChanged(object sender, EventArgs e)
        {

        }

       
    }
}
